#include <Area_Beta.h>

#include <World.h>

#include <PlayerInterface.h>

#include <EnemyShip.h>

#include <glut.h>
#include <Camera.h>

#include <LoadGameObject.h>
#include <SetLoadingScreen.h>

#include <MenuButton.h>


Beta::Beta(World& gameworld)
:Area(gameworld)
{
}

Beta::~Beta()
{
}
		
std::string Beta::GetName()
{
	return "Beta";
}

void Beta::Init()
{
	world.AddCommand( new SetLoadingScreen( &world, 1 ) );
	Global::GameWorldSize = vec2(10000,10000);

	//for(unsigned j = 0; j < 10; ++j)
	//for(unsigned i = 0; i < 10; ++i)
	//{
	//	EnemyShip* r = CreateAreaObject( EnemyShip );
	//	r->SetPosition( vec2(50 + i * 5, 50 + j * 5) );
	//	r->SetColor( 0.2f + 0.8f*Global::GetRandomFloat(), 0.2f + 0.8f*Global::GetRandomFloat(), 0.2f + 0.8f*Global::GetRandomFloat() );
	//	if(i == 0 && j == 0)
	//		External::player->SetControlTarget(r);
	//}
	
	EnemyShip* r = CreateAreaObject( EnemyShip );
	r->SetPosition( vec2(5, 5) );
	External::player->SetControlTarget(r);

	for(unsigned j = 0; j < 10; ++j)
	for(unsigned i = 0; i < 10; ++i)
		world.AddCommand( new LoadGameObject<EnemyShip>( this, vec2(50 + i * 5, 50 + j * 5) ) );


	//starfields.push_back( Starfield( vec2(500,0), 500.0f, 500.0f, 250, 0 ) );
	//starfields.push_back( Starfield( vec2(0,500), 500.0f, 500.0f, 250, 0 ) );
	//starfields.push_back( Starfield( vec2(0,0), 500.0f, 500.0f, 250, 0 ) );
	//starfields.push_back( Starfield( vec2(500,500), 500.0f, 500.0f, 250, 0 ) );

	starfields = MakeStarfields(10,1000,1000);
	//for(unsigned j = 0; j < 10; ++j)
	//for(unsigned i = 0; i < 10; ++i)
	//{
	//starfields.push_back( Starfield( vec2(i*1000,j*1000), 1000.0f, 1000.0f, 1000, 0 ) );
	//}
	
	world.AddCommand( new SetLoadingScreen( &world, 0 ) );
}

void Beta::UpdateArea()
{
}

void Beta::Cleanup()
{
}

void Beta::CustomDraw()
{
	for(unsigned i = 0; i < starfields.size(); ++i)
	{
		if( starfields[i].IsNearby(External::camera->GetPos(), 1000) )
		{
			starfields[i].Draw();
		}
	}
	/*
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	int w = glutGet(GLUT_WINDOW_WIDTH);
	int h = glutGet(GLUT_WINDOW_HEIGHT);
	gluOrtho2D(0, w, h, 0);
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();

	glColor3f(0.5,0.5,0.5);
	glPointSize(10);
	glBegin(GL_POINTS);
	glVertex2f( Global::Mouse::ScreenPos.x, Global::Mouse::ScreenPos.y );
	glEnd();
	glPointSize(1);
	
	glPopMatrix();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	*/
}